#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

ll dp[55][50010];
ll a[55];
ll vis[500010];
bool cmp(ll x,ll y){
    return x>y;
}

int main()
{
    IOS;
    ll n,m;
    ll cnt=0,mi,cc;
    cin>>m>>n;
    for(ll i=0;i<n;i++){
        cin>>mi>>cc;
        while(cc--){
            a[++cnt]=mi;
        }
    }
    sort(a+1,a+cnt+1,cmp);
    for(ll i=1;i<=cnt;i++){
        for(ll j=m;j>=a[i];j--){
            if(dp[i-1][j-a[i]]+a[i]>dp[i][j]){
                dp[i][j]=dp[i-1][j-a[i]]+a[i];
                vis[j]=a[i];
            }
            else {
                vis[j]=vis[j-a[i]];
            }
        }
    }
    if(dp[n][m]!=m){
        cout<<"> <"<<endl;
    }
    else {
        ll ans=0;
        ll fa=m;
        while(vis[fa]!=0){
            fa=vis[fa];
            ans++;
        }
        cout<<ans<<endl;
    }
    getchar();
    getchar();
    return 0;
}
